﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Enterprise.Modules;
using Enterprise;
using System.IO;
using Enterprise.Templates;

namespace Enterprise.Modules
{
    public partial class _HtmlContent : ModuleBase
    {
        private HtmlContent _module;

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            updateViews();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            _module.Html = txtHtml.Text;
            _module.SaveData();
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ViewMode = ViewMode.Readonly;
            multiview.SetActiveView(readonlyView);
        }

        public override IModule Module
        {
            set{_module = (HtmlContent)value;}
            get { return (HtmlContent)_module; }
        }

        public override bool HasAdminView
        {
            get { return true; }
        }

        public override string InfoUrl
        {
            get
            {
                return "";
            }
        }

        private void updateViews()
        {
            string pageId = Request.QueryString["PageID"];

            if (ViewMode == ViewMode.Edit)
            {
                multiview.SetActiveView(editView);
                txtHtml.Text = _module.Html;
            }
            else
            {
                multiview.SetActiveView(readonlyView);
                litContent.Text = _module.Html.Replace("{0}", pageId);
            }
        }
    }
}